<?php 

require("./PHP/Conn.php");
//require ("./PHP/php_users.php");
function crea_role()
{  
    $roles = procedure_call("ROLESSISTEMA");
    $roles_ = Array("DEFAULT");
    $privilegios = procedure_call("PRIVSISTEMA"); 
    $privilegios_ = Array("DEFAULT");
    //$tablespaces = procedure_call("TABLESPACES"); 
    //$tablespaces_ = Array();
    $tablas = procedure_call("TODASTABLAS"); 
    $tablas_ = Array();
    foreach($roles as $r)
        array_push($roles_, implode($r));
    foreach($privilegios as $p)
        array_push($privilegios_, implode($p));
//    foreach($tablespaces as $t)
//        array_push($tablespaces_, implode($t));
    foreach($tablas as $t0)
    { 
        $tv = implode($t0);
        array_push($privilegios_,"SELECT ON ".$tv);
        array_push($privilegios_,"DELETE ON ".$tv);
        array_push($privilegios_,"INSERT ON ".$tv);
        array_push($privilegios_,"UPDATE ON ".$tv);
        array_push($privilegios_,"ALL ON ".$tv);
    }
    $str =  '<form role="form">';
    $str.=      '<div class="form-group">';
    $str.=          inputBonito("Role", "Nombre de Rol", "text","nombreRol");
    $str.=          combobox(Array("NOT IDENTIFIED","IDENTIFIED BY","IDENTIFIED EXTERNALLY","IDENTIFIED GLOBALLY"),"IDENTIFIED");
    $str.=          inputBonito("claveRole", "Inserte una Clave", "password", "rol-clave");
    $str.=          inputBonito("claveRole2", "Confirme su Clave", "password","rol-clave1");
    $str.=          '<div class="divScroll"><div class="form-group">';
    $str.=              selectBox($privilegios_,"privroles","Privilegios Disponibles").'<span class="glyphicon glyphicon-plus-sign" onclick="addNuevaRow('."'privroles'".')"></span>';
    $str.=              Tabla(Array("Row","Privilege"),Array(),"","tabla-agrega-rol");
    $str.=          '</div></div>';
    $str.=          '<div class="divScroll"><div class="form-group">';
    $str.=              selectBox($roles_,"rolesroles","Roles Disponibles").'<span class="glyphicon glyphicon-plus-sign" onclick="addNuevaRow('."'rolesroles'".')"></span>';
    $str.=              Tabla(Array("Row","Roles"),Array(),"","tabla-agrega-rol-roles");
    $str.=          '</div></div>';
    $str.=      '</div>';
    $str.=  '</form> ';  
    //echo json_encode($roles);
    echo $str;
}
function TablaRole($theads , $tbodys, $DivNombre)
{  
    $cantCol=0;
    $cantIns=0;
    $accion=$DivNombre;
            /*"alert('<?php PopUpUsuario()?>')";*/ 
    $str = '<div class="table-responsive"> ';
        $str .= '<table id="TablaRoles "class="table table-striped">';
            $str.= ' <thead>';

            //lleno thead
            $resultado = count($theads);
             $bool = true;
            foreach($theads as $thead)
            {              
                if($bool)
                {
                    $str.= '<tr>';
                  $bool = false;
                }
                $str.='<th>'.$thead.'</th>';
                $cantCol++;
                if($cantCol == $resultado)
                {
                    $str.='</tr>';
                }
                
            }
            $str.='</thead>';

            //lleno tbody
            $cont=1;
            $str.='<tbody>';
            foreach ($tbodys as $tbody) {
                //echo $tbodys[$cont]."</br>";
                //echo $tbody["string"]."</br>";
                if($cantIns==0)
                {
                    $tprueba = "Hola";
                    $cantIns++;
                    $str.='<tr value='.'"'.$tbodys[$cont].'"'.'>';
                    //data-toggle="modal" data-target="#myModalModificarRol"
                    $str.='<td>'.$tbody.'</td>'; 
                                      
                 }elseif( $cantIns != $cantCol && $cantIns <= $cantCol)
                    {
                       $cantIns++;
                       $str.='<td>'.$tbody.'</td>'; 
                           if($cantIns == $cantCol)
                           {
                                $str.='</tr>';  
                                $cantIns = 0;
                           }
                           $cont += 2;
                    }   
                    
            }
            $str.='</tbody>';
       
        $str.='</table>';
    $str.='</div>';
echo ($str);
//$divPrincipal->echo ($str);
}

  function modificar_rol($nombreRol){
      echo "hello, modificando el rol: ".$nombreRol;
  }
  
  
  